Skip to content

fix(security): replace permissive CORS wildcard with explicit allowlist#121

Merged
epugh merged 2 commits into
apache:mainfrom
adityamparikh:fix/security-cors-allowlist
May 8, 2026
Merged

fix(security): replace permissive CORS wildcard with explicit allowlist#121
epugh merged 2 commits into
apache:mainfrom
adityamparikh:fix/security-cors-allowlist

Conversation

@adityamparikh
Copy link
Copy Markdown
Contributor

Summary

The HTTP transport's CORS configuration used setAllowedOriginPatterns(\"*\") together with allowCredentials=true. This is Spring's escape hatch around the MDN/W3C CORS rule that wildcard origins cannot be combined with credentials, and it triggers CWE-942 per the OWASP HTML5 Security Cheat Sheet.

This PR switches to the strict setAllowedOrigins(...) API backed by a configurable allowlist (mcp.cors.allowed-origins / MCP_CORS_ALLOWED_ORIGINS) that defaults to the MCP Inspector's local proxy ports (http://localhost:6274,http://127.0.0.1:6274).

Allowed methods are tightened to GET, POST, DELETE, OPTIONS and allowed headers to Authorization, Content-Type, Mcp-Session-Id, MCP-Protocol-Version, Last-Event-ID — the explicit set required by the MCP Streamable HTTP transport spec. Operators running the MCP server with browser-based clients or dashboards beyond the Inspector add origins via the env var. Bearer-token auth flows continue to work because allowCredentials is preserved.

Test plan

  • `./gradlew spotlessApply` clean
  • `./gradlew build` passes (full test suite, 43s)
  • Manual verification with MCP Inspector at http://localhost:6274 still completes a request flow

References

🤖 Generated with Claude Code

The HTTP CORS configuration used setAllowedOriginPatterns("*") with
allowCredentials=true, which is Spring's escape hatch around the
browser rule that wildcards can't be used with credentials (MDN CORS
spec). Replace with the strict setAllowedOrigins API and a configurable
allowlist that defaults to the MCP Inspector's local proxy port.

Methods and headers also tightened to the explicit set used by the
Streamable HTTP transport per the MCP specification, replacing
"*" wildcards.

Operators add additional origins via the MCP_CORS_ALLOWED_ORIGINS env
var or the mcp.cors.allowed-origins property.

Refs:
- MDN CORS — Credentialed requests and wildcards
- CWE-942: Permissive Cross-domain Policy with Untrusted Domains
- OWASP HTML5 Security Cheat Sheet (CORS)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: adityamparikh <aditya.m.parikh@gmail.com>
@epugh epugh merged commit 8eff997 into apache:main May 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants